package com.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.entity.Preorder;
import com.entity.SearchParms;
import com.entity.Ground;
import com.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface UserMapper extends BaseMapper<User> {
    User searchByUname(String uname);

    // 忘记密码
    @Update("UPDATE user SET psw = #{psw} WHERE mobile = #{mobile}")
    void forget(String psw, String mobile);

    // 更新场地预约管理
    @Update("UPDATE preorder SET p_state = 0 WHERE g_id = #{GID} AND t_id = #{TID} AND p_date = #{PDATA}")
    void UpdataP(String GID, String TID, String PDATA);

    // 添加预约记录
    @Insert("INSERT INTO preorder VALUES(#{gId},#{tId},#{uId},#{pDate},1)")
    List<Preorder> addPreorder(int gId, int tId, int uId, String pDate);

    //查询个人的所有场地预约
    @Select("select c_name,uname,start_time,end_time,p_date,p_state,g_id,t_id from preorder,user,ground,time_tb where ground.id = preorder.g_id and time_tb.id = preorder.t_id and user.id= preorder.u_id and user.uname = #{uname}")
    List<Map<String, Object>> PInfo(String uname);

    //根据校区和类型查询
    @Select("select * from ground where c_campus = #{cCampus} and c_type = #{cType}")
    List<Ground> search(String cCampus, String cType);

    //查询全部
    @Select("select * from ground")
    List<Ground> getAllGround();

    //根据类型查询
    @Select("select * from ground where c_type = #{cType}")
    List<Ground> getByType(String cType);

    //根据校区查询
    @Select("select * from ground where c_campus = #{cCampus}")
    List<Ground> getByCampus(String cCampus);

}
